from django.shortcuts import render

from django.http import JsonResponse

from django.views import View

from booktest.models import BookInfo, HeroInfo
class BookView(View):
    def get(self, request):

        book = BookInfo.objects.create(
            btitle='秦岭神树',
            bpub_date='2019-1-1'
        )
        print(book)


        hero = HeroInfo.objects.create(
            hname='胖子',
            hgender=0,
            hcomment='逗乐',
            hbook=book
        )

        return JsonResponse({'data': hero.hname})



        book = BookInfo.objects.get(id=5)
        book.btitle = '盗墓笔记'
        book.save()


        #删除

        book = BookInfo.objects.get(id=5)
        book.delete()

        # 查询

        BookInfo.onjects.get(id=1)

